package com.feifan.monthhelper.db.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.feifan.monthhelper.bean.db.DayRecordBean;

import java.util.List;

@Dao
public interface DayRecordDao {

    @Query("Select * from day_record")
    List<DayRecordBean> getAll();

    @Query("Select * from day_record Where create_date = (:date)")
    DayRecordBean loadByDate(long date);

    @Query("Select * from day_record Where state = (:state)")
    List<DayRecordBean> getAllMenstrualDay(int state);

    @Query("Select * from day_record WHERE protects LIKE '%避孕药%' OR protects LIKE '%无措施%' OR protects LIKE '%避孕套%' LIMIT (:size) OFFSET (:offset)")
//    @Query("Select * from day_record WHERE LENGTH (protects) > 5 LIMIT (:size) OFFSET (:offset)")
    List<DayRecordBean> loadLoveByPage(int offset, int size);

    @Query("Select * from day_record Where create_date >= (:startDate) And create_date <= (:endDate)")
    List<DayRecordBean> loadBy(long startDate, long endDate);

    @Query("Select * from day_record Where create_date >= (:startDate)")
    List<DayRecordBean> loadFrom(long startDate);

    @Query("Select * from day_record Where create_date >= (:startDate) And create_date <= (:endDate) And protects <> ''")
    List<DayRecordBean> loadLoveBy(long startDate, long endDate);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<DayRecordBean> dayRecordBeans);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(DayRecordBean dayRecordBean);

    @Delete
    void deleteAll(List<DayRecordBean> dayRecordBeans);

    @Delete
    void delete(DayRecordBean... dayRecordBeans);

//    @Delete
//    void clear();

    @Update
    void update(DayRecordBean... dayRecordBeans);

//    @Query("update videobean set id =:videoId where date=:uid")
//    void updateCustom(String videoId, int uid);
}
